<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?php
	if($_GET['thamso']=="tim_kiem")
	{
		if($_GET['tu_khoa']=="")
		{
			$tu_khoa_input="Từ khóa";
		}
		else
		{
			$tu_khoa_input=$_GET['tu_khoa'];
		}
	}
	else
	{
		$tu_khoa_input="Từ khóa";
	}
?>
<?php
$tu_khoa=$_GET['tu_khoa'];
if ($tu_khoa=="" or $tu_khoa=="Từ khóa")
{
	chuyentrang("?thamso=quanly");
}
$mang_tk=explode(" ",$tu_khoa);
$chuoi_or="";
for($f=0;$f<count($mang_tk);$f++)
	{
		$q=$mang_tk[$f];
		if($q!="")
		{
		$chuoi_or=$chuoi_or." tensp like '%$q%' or ";
		}
	}
	$chuoi_or="tensp like '".$tu_khoa."' or ".$chuoi_or;
	$chuoi_or=substr($chuoi_or,0,-3);
?>
<?php 
	function tinh_so_trang($so_gioi_han)
		{
			$sql="select count(*) from dm_sanpham";
			$sql1=mysql_query($sql);
			$data=mysql_fetch_row($sql1);
			$st=ceil($data[0]/$so_gioi_han);
			return $st;
		}
	$ssp_td=1;
	$sd=15;
	$so_gioi_han=$ssp_td*$sd;
	if($_GET['trang']=="")
	{
		$vtbd=0;
	}
	else 
	{
		$vtbd=($_GET['trang']-1)*$so_gioi_han;
	}
	$st=tinh_so_trang($so_gioi_han);
?>
<a href="?thamso=themsp2"><input type="button" value="Thêm sản phẩm" style="height:30px; width:200px"/></a>
 <center>
 <table width="980px" style="clear:left;" >
		<tr>
			<td width="440px">
                  <div>
					<form action="">
						<input type="hidden" name="thamso" value="tim_kiem">
						<b>Chọn : </b><input value="<?php echo $tu_khoa_input;?>" name="tu_khoa" style="width:200px; height:25px;" onfocus="if (this.value=='<?php echo $tu_khoa_input;?>'){this.value=''};this.style.backgroundColor='#fffde8';" onblur="this.style.backgroundColor='#ffffff';">		
						
						<input type="submit" value="Tìm kiếm" style="width:100px; height:25px;">
					</form>
				</div>
			</td>
		</tr>
	</table>
	<table width="990px" border="1" style="margin-top:6px" id="er" bordercolor="#00CC00">
		<tr>
			<td width="100px" align="center"><b>Hình ảnh</b></td>
			<td width="300px" align="left"><b>Tên sản phẩm</b></td>
			<td width="380px" align="left"><b>Thông tin</b></td>
			<td width="100px" align="center"><b>Sữa</b></td>
			<td width="100px" align="center"><b>Xóa</b></td>
		</tr>
		<?php 
			
			$sql="select * from dm_sanpham where $chuoi_or order by idsp limit $vtbd,$so_gioi_han";
			$sql1=mysql_query($sql);
			while($tv_2=mysql_fetch_array($sql1))
			{
				$link_hinh="../image/ha_sp/".$tv_2['hinh'];
				$link_sua="?thamso=suasp&id=".$tv_2['idsp'];
				$link_xoa="?thamso=xoasp&id=".$tv_2['idsp'];
				?>
					<tr>
						<td align="center">
							<a href="<?php echo $link_sua; ?>" >
								<img src="<?php echo $link_hinh; ?>" width="90px" height="90px" border="0"/>
							</a>
						</td>
						<td align="left" >
							<a href="<?php echo $link_sua; ?>" class="thua__link_1">
								<?php echo $tv_2['tensp']; ?>
							</a>
						</td>
						<td align="left" ><?php echo $tv_2['thongtin']; ?></td>
						<td align="center">
							<a href="<?php echo $link_sua; ?>" class="sua_xoa" >
								Sữa
							</a>
						</td>
						<td align="center">
							<a href="<?php echo $link_xoa; ?>" class="sua_xoa" >
								Xóa
							</a>
						</td>
					</tr>
				<?php
			}
		?>
		
	</table>
    <?php
				echo "<div id='trang'>";
		for($i=1;$i<=$st;$i++)
		{
			$link="?thamso=quanly&trang=$i";
			echo "<a href='$link' class='hello'><font size='4px'>";
			echo $i;
			echo "</font></a>";echo"  ";
		}
	echo "</div>";
	?>
</center>
<script>
	table_css_2("er");
</script>

	